import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:ls_work/net/response/department_list_data.dart';
import 'package:ls_work/net/response/response_data.dart';

import '../../net/response/employee_list_data.dart';
import '../../net_configs.dart';

class ServiceOrderModel extends BaseMvvmModel {
  @override
  void onCleared() {}

  ///员工列表
  Future<List<EmployeeListData>> getEmployeeList(String officeId) async {
    var map = {"officeId": officeId};
    var data = await HttpGo.instance.postData(ServiceOrderApis.employeeList,
        data: map, options: urlencodedHeader);
    var bean = ResponseBean.fromJson(data);
    if ("0" == bean.code) {
      var list = (bean.data == null ? [] : bean.data as List)
          .map((e) => EmployeeListData.fromJson(e))
          .toList();
      return list;
    } else {
      throw bean.msg??"";
    }
  }

  ///派单
  Future<ResponseBean> sendOrder(String officeUserId,String officeId,String id) async {
    var map = {
      "officeUserId":officeUserId,
      "officeId":officeId,
      "id":id,
      "type":"1"
    };
    var data = await HttpGo.instance.postData(ServiceOrderApis.sendOrder,
        data: map);
    var bean = ResponseBean.fromJson(data);
    if ("0" == bean.code) {
      return bean;
    } else {
      throw bean.msg??"";
    }
  }

  ///派单人拒单
  Future<ResponseBean> officeRefuceOrder(String noOpenCause,String id) async {
    var map = {
      "noOpenCause":noOpenCause,
      "id":id,
      "type":"2"
    };
    var data = await HttpGo.instance.postData(ServiceOrderApis.officeRefuse,
        data: map);
    var bean = ResponseBean.fromJson(data);
    if ("0" == bean.code) {
      return bean;
    } else {
      throw bean.msg??"";
    }
  }


  ///部门列表
  Future<List<DepartmentListData>> departmentList() async {
    var map = {};
    var data = await HttpGo.instance.postData(
      ServiceOrderApis.departmentList,
      data: map,
    );
    var bean = ResponseBean.fromJson(data);
    if ("0" == bean.code) {
      var list = (bean.data == null ? [] : bean.data as List)
          .map((e) => DepartmentListData.fromJson(e))
          .toList();
      return list;
    } else {
      throw bean.msg??"";
    }
  }

  Future<bool> canSendOrder() async {
    var map = {};
    var data = await HttpGo.instance.postData(ServiceOrderApis.canSenOrder,data: map);
    var bean = ResponseBean.fromJson(data);
    if ("0" == bean.code) {
      if(bean.data['isPd']=="1"){
        return true;
      }else{
        return false;
      }

    } else {
      return false;
    }
  }


  ///全部员工列表
  Future<List<EmployeeListData>> wholeEmployeeList(int type,String customer,int page,int rows) async {
    var map = {
      "type":type,
      "customer":customer,
      "page":page,
      "rows":rows
    };
    var data = await HttpGo.instance.postData(ServiceOrderApis.wholeEmployeeList,data: map);
    var bean = ResponseBean.fromJson(data);
    if ("0" == bean.code) {
      var list = (bean.data['rows'] == null ? [] : bean.data['rows'] as List)
          .map((e) => EmployeeListData.fromJson(e))
          .toList();
      return list;
    } else {
      throw bean.msg??"";
    }
  }



}
